package com.rockwell.sniffyHunter.test;

import java.util.HashMap;
import java.util.Map;

import junit.framework.Assert;

import com.rockwell.sniffyhunter.model.Picker;
import com.rockwell.sniffyhunter.model.Robot;
import com.rockwell.sniffyhunter.utils.DetectionIndex;
import com.rockwell.sniffyhunter.utils.IDetector;
import com.rockwell.sniffyhunter.utils.IRobotCommander;
import com.rockwell.sniffyhunter.utils.IRobotSensors;
import com.rockwell.sniffyhunter.utils.PickerState;

import android.annotation.SuppressLint;

public class PickerStateTester extends UnitTestLooper {
	private IRobotSensors 			sensor;
	private FakeTreasureDetector	treasureDetector;
	private Map<Integer, IDetector>	colorDetectors;
	private FakeTreasureCollector 	treasureCollector;
	private IRobotCommander 		robotCommander;
	private Robot 					robot;	
	private Picker 					picker;
	
	@SuppressLint("UseSparseArrays") @SuppressWarnings("serial")
	@Override
	public void setUp() {
		treasureDetector		= new FakeTreasureDetector();
		sensor 					= new FakeRobotSensors();
		colorDetectors 			= new HashMap<Integer, IDetector>() {
								  {
									  put(DetectionIndex.TREASURE, treasureDetector/*treasure detector*/);
									  put(DetectionIndex.OBSTACLE, new FakeColorDetector()/*obstacle detector*/); 
									  put(DetectionIndex.MAZE1, new FakeColorDetector()/*maze1 detector*/);
									  put(DetectionIndex.MAZE2, new FakeColorDetector()/*maze2 detector*/);
									  put(DetectionIndex.MAZE3, new FakeColorDetector()/*maze3 detector*/);
									  put(DetectionIndex.DROPZONE, new FakeColorDetector()/*dropZone detector*/);
									  put(DetectionIndex.MAZE_EXIT, new FakeColorDetector()/*dropZone detector*/);
								  }};
		robotCommander 			= new DummyRobotCommander();
		treasureCollector 		= new FakeTreasureCollector();
		robot 					= new Robot(0, 0, 
									1 /*start Zone*/,
									sensor, 
									robotCommander, 
									null/*maze*/, 
									null/*solver*/, 
									colorDetectors, 
									treasureCollector);	
		picker 					= new Picker(robot);
	}
	
	@Override
	public void tearDown() {

	}
	
	public void testPickerState() {
		Assert.assertEquals(picker.getStateMachine(), PickerState.START);
		
		picker.PerformAction();
		Assert.assertEquals(picker.getStateMachine(), PickerState.MOVE_TO_TREASURE);
		
		treasureDetector.m_isPresent = true;
		loopUntilCondition(picker, PickerState.PICK);
		Assert.assertEquals(picker.getStateMachine(), PickerState.PICK);
		
		treasureDetector.m_isPresent = false;
		loopUntilCondition(picker, PickerState.MOVE_BACK_TO_SNIFF);
		Assert.assertEquals(picker.getStateMachine(), PickerState.MOVE_BACK_TO_SNIFF);
		
		loopUntilCondition(picker, PickerState.START);
		Assert.assertEquals(picker.getStateMachine(), PickerState.START);
	}
}
